<template>
  <div class="edit">
    <h1
      style="
        font-weight: 700;
        font-style: normal;
        font-size: 24px;
        color: #344563;
        margin-bottom: 30px;
      "
    >
      审核库存
    </h1>
    <div class="edit-box">
      <div class="form">
        <el-form
          :label-position="labelPosition"
          label-width="80px"
          :model="formData"
        >
          <el-form-item label="盘点日期">
            <el-col :span="11" style="width: 100%">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="formData.time"
                style="width: 100%"
                value-format="yyyy-mm-dd"
                disabled
              ></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="盘点单号">
            <el-input v-model="formData.code" disabled></el-input>
          </el-form-item>
          <el-form-item label="制单人">
            <el-input v-model="formData.mperson" disabled></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="form">
        <el-form
          :label-position="labelPosition"
          label-width="80px"
          :model="formData"
        >
          <el-form-item label="审查状态">
            <el-select
              v-model="formData.status"
              placeholder="审核状态"
              style="width: 100%; padding: 0"
            >
              <el-option
                :key="v"
                v-for="v in select2"
                :label="
                  v == 1
                    ? '待审核'
                    : v == 2
                    ? '审核通过'
                    : v == 3
                    ? '拒绝审核'
                    : '--'
                "
                :value="v"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="审查人">
            <el-input v-model="formData.reviewer" disabled></el-input>
          </el-form-item>
          <el-button
            style="margin-right: 20px; width: 100px; margin-left: 150px"
            @click="cancel"
            >取消</el-button
          >
          <el-button
            type="danger"
            style="background: #6554c0; border: none; width: 100px"
            @click="save"
            >保存</el-button
          >
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      labelPosition: "left",
      formData: {
        time: "",
        code: "",
        mperson: "",
        status: "",
        reviewer: "",
      },
      //备份刷新页面防丢失数据
      formData1: [],
      select2: [1,2,3],
      ID:''
    };
  },
  methods: {
    cancel: function () {
      this.$router.push("/home/Kcpd");
    },
    //时间转换
    switchDate: function (sj) {
      var now = new Date(sj);
      var year = now.getFullYear();
      var month = now.getMonth() + 1;
      var date = now.getDate();
      return year + "-" + month + "-" + date;
    },

    //渲染修改界面
    getEdit: function (v) {
      this.formData.time = this.switchDate(v.inventoryDate);
      this.formData.code = v.inventoryNo;
      this.formData.mperson = v.preparedBy;
      this.formData.reviewer = v.reviewedBy;
      this.formData.status =
        v.auditStatus == 2
          ? "审核完成"
          : v.auditStatus == 1
          ? "待审核"
          : v.auditStatus == 3
          ? "拒绝审核"
          : "";
    },
    getData: function () {
      //获取数据
      let Data = this.$store.state.xjqVuex.stock;
      if (Data == "") {
        this.getEdit(this.formData1);
      } else {
        this.getEdit(Data);
      }
    },
    //修改保存
    save: function () {
      this.$axios({
        url: "/WInventoryManag/update",
        method: "post",
        data: {
          //审核状态(1:待审核，2：审核通过，3，审核拒绝
          auditStatus: this.formData.status,
          //id
          inventoryNo: this.formData.code,
          reviewedById:this.ID
        },
      }).then(({ data }) => {
        console.log(data);
        if (data.code == 0) {
          this.$message.success("审核成功！");
          setTimeout(() => {
            this.$router.push("/home/Kcpd");
          }, 1000);
        } else {
          this.$message.error(data.msg);
        }
      });
    },
    //渲染下拉
    getSelect: function () {
      this.$axios({
        url: "/personal/pdept",
      }).then(({ data }) => {
        this.select1 = data.data;
      });
      // this.$axios({
      //   url: "/wReceiptManagement/status",
      //   method: "post",
      // }).then(({ data }) => {
      //   this.select2.push(data.data[0].auditStatus);
      //   this.select2.push(data.data[1].auditStatus);
      //   this.select2.push(data.data[3].auditStatus);
      // });
    },
  },
  mounted: function () {
    this.getData();
    this.getSelect();
  },
  created: function () {
    //创建后获取session备份数据
    this.formData1 = JSON.parse(sessionStorage.getItem("stock"));
    this.ID=JSON.parse(sessionStorage.getItem('user'))[0].id

  },
};
</script>
<style lang="less" scoped>
.edit {
  padding: 40px;
}
.edit-box {
  display: flex;
  margin-bottom: 30px;
}
.form {
  height: auto;
  flex: 1;
  margin-right: 150px;
}
</style>